/*
 * BPlusTreeTestString.cpp

 *
 *      Author: carlos
 */

#include "BPlusTreeTestString.h"
#include "../../src/logical_layer/bplustree/BPlusTree.h"
#include "../../src/physical_layer/PersistorBase.h"
#include "../../src/logical_layer/bplustree/PersistorPool.h"
#include "../../src/utils/ConfigurationMannagerPool.h"
#include "../../src/utils/StringUtils.h"
#include "../../src/logical_layer/bplustree/ElementFactory.h"

BPlusTreeTestString::BPlusTreeTestString() {
	this->bplus = NULL;
}

BPlusTreeTestString::~BPlusTreeTestString() {
}

void BPlusTreeTestString::run() {
	this->testSimple();
}

void BPlusTreeTestString::testSimple() {
	cout << "**********INICIANDO SIMPLE TEST PARA BPLUSTREE-STRING" << endl;
	if (this->bplus != NULL) {
		delete this->bplus;
		PersistorPool::dropInstance(ELEMENT);
	}
	cout << " TESTING testSimpleElements" << endl;
	system("rm testTree");
	system("rm testTree.fs");
	this->bplus =
			new BPlusTree(
					ConfigurationMannagerPool::getInstance(ELEMENT)->getBufferSizeTree(),
					"testTree", ELEMENT);

	bplus->insert(ElementFactory::createElement(ELEMENT, "palabra", "1", 1));
	bplus->insert(
			ElementFactory::createElement(ELEMENT, "palabrabrita", "1,2,3,4",
					7));
	bplus->insert(
			ElementFactory::createElement(ELEMENT, "palabrabritas", "1,2,3,4",
					7));
	bplus->insert(ElementFactory::createElement(ELEMENT, "casa", "1,2,3,4", 7));

	bplus->insert(
			ElementFactory::createElement(ELEMENT, "patio", "1,2,3,4", 7));

	bplus->insert(
			ElementFactory::createElement(ELEMENT, "mundo", "1,2,3,4", 7));
	bplus->insert(
			ElementFactory::createElement(ELEMENT, "lugar", "1,2,3,4", 7));

	bplus->insert(
			ElementFactory::createElement(ELEMENT, "extrano", "1,2,3,4", 7));

	bplus->insert(
				ElementFactory::createElement(ELEMENT, "puerto", "1,2,3,4", 7));
	bplus->exportTree();
	cout << "**********SIMPLE TEST PARA BPLUSTREE-STRING    OK" << endl;

	/*
	 GenericKey g1("casa");
	 LeafNode* leafNode=bplus->find(g1);
	 if(leafNode!=NULL){
	 cout<<"encontrado OK"<<endl;
	 leafNode->nextElement();
	 leafNode->exportNode();
	 }
	 */

}
